<template>
<div>
  <el-table ref="multipleTable" :data="list">
    <el-table-column prop="teaName" label="姓名"></el-table-column>
    <el-table-column prop="teacherType" label="身份" :formatter="teacherTypeFormatter"></el-table-column>
    <el-table-column prop="time" label="值班时间"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button
            size="small"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
        >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</div>
</template>

<script>
import {getRota,deleteTeacherRota} from "../../api/rota";
import {ElMessage} from "element-plus";
export default {
  name: "rotaList",
  data() {
    return{
      list:[{
        id:'',
        teaId:'',
        timeId:'',
        teacherType:'',
        teaName:'',
        time:''
      }]
    }
  },
  created() {
    this.getRotaList()
  },
  methods: {
    getRotaList(){
        getRota().then(res=>{
          console.log(res)
          if(res.code === 1){
            this.list = res.data
          } else {
            ElMessage.error(res.message)
          }
        })
    },
    teacherTypeFormatter(x){
      console.log(x)
      if(x.teacherType === 2){
        return '咨询师'
      } else if(x.teacherType === 3) {
        return '中心管理员'
      } else if(x.teacherType === 4) {
        return '助理'
      } else if(x.teacherType === 5){
        return '初访师'
      } else {
        return '未知'
      }
    },
    handleDelete(index,row){
      console.log(row)
      deleteTeacherRota(row.id).then(res=>{
        console.log(res)
        if(res.code === 1){
          this.getRotaList()
          ElMessage.success(res.message)
        } else {
          ElMessage.error(res.message)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>